package util;

import java.sql.Connection;
import java.sql.Driver;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Properties;

public class ConnectDataBase {

	public Connection connection=null;
	private Statement statement=null;
	private ResultSet resultSet=null;

	public ConnectDataBase() {
		try {
			Class.forName("org.sqlite.JDBC");
			connection = DriverManager
					.getConnection("jdbc:sqlite:D:\\sqllite database\\data_hotel.db");
			statement = connection.createStatement();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public Connection getConnection() {
		return connection;

	}

	public void closeConnection() {
		try {
			statement.close();
			connection.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	// delete - update - insert
	public void query_update(String sql) {
		try {

			statement.executeUpdate(sql);

		} catch (SQLException e) {
			System.err.println(e.getClass().getName() + ": " + e.getMessage());
			System.exit(0);
		} 

	}

	// delete - update - insert
	public ResultSet query_select(String sql) {
		try {
			resultSet = statement.executeQuery(sql);
			System.err.println(sql);
		} catch (SQLException e) {
			System.err.println(e.getClass().getName() + ": " + e.getMessage());
			System.exit(0);
		}
		return resultSet;
	}

}
